package com.hfzy.ihk.web.websocket.controller;

import com.hfzy.ihk.common.util.CommonUtils;
import com.hfzy.ihk.common.util.string.StringUtil;
import com.hfzy.ihk.facade.websocket.linkcall.service.WebSocketService;
import com.hfzy.ihk.web.websocket.constant.Constants;
import com.hfzy.ihk.web.websocket.support.SampleCache;
import com.hfzy.ihk.web.websocket.support.WebSocketManager;
import com.hfzy.ihk.web.websocket.utils.SpringWebSocketUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.socket.WebSocketSession;

import javax.servlet.http.HttpServletRequest;
import java.net.URLDecoder;

/**
 * Created by YANFA on 2018/9/6.
 */
@RestController
@RequestMapping("analysePushData")
public class AnalysePushDataController {

    private static final Logger logger = LoggerFactory.getLogger(AnalysePushDataController.class);

    @Autowired
    WebSocketService webSocketService;

    /**
     * 分析服务项目推送数据到客户端
     * @param sessionId
     * @param jsonStr
     * @return
     */
    @RequestMapping("pushToBrowserBySessionId")
    public String pushToBrowserBySessionId(String sessionId, String jsonStr, HttpServletRequest httpServletRequest){
        try {

            Boolean bl = webSocketService.pushToBrowserBySessionId(sessionId, jsonStr);
            if (bl)
                return Constants.success;
            else
                return Constants.fail;
        }catch (Exception e){
            logger.error("推送语音分析结果失败sessionId:{},jsonStr:{}",sessionId,jsonStr,e);
            return Constants.fail;
        }
    }
}
